package com.kedacom.ctsp.authority.service.simple;

import com.kedacom.ctsp.authority.service.DataScopeService;
import com.kedacom.ctsp.authz.access.DataAccessScopeEnum;
import com.kedacom.ctsp.authz.access.DataAccessUtil;
import com.kedacom.ctsp.authz.entity.AuthResource;
import com.kedacom.ctsp.authz.entity.Authentication;
import com.kedacom.ctsp.orm.param.Term;
import com.kedacom.ctsp.orm.param.TermEnum;
import com.kedacom.ctsp.web.entity.*;
import org.springframework.stereotype.Service;

import java.util.Optional;
import java.util.Set;

/**
 * 权限自定义获取工具类
 */
@Service
public class DataScopeServiceImpl implements DataScopeService {

    /**
     * 数据权限
     *
     * @param auth
     * @param resourceSign
     * @return
     */
    @Override
    public Term getDataScopeTerm(Authentication auth, String resourceSign) {
        //TODO
        //Optional<Set<AuthResource>> resources = auth.getResources(resourceSign);
        Term term = null;
//        if (resources.isPresent()) {
//            DataAccessScopeEnum scope = DataAccessUtil.getDataScopeByResources(resources.get());
//
//            switch (scope) {
//                default:
//                case SELF:
//                    term = Term.build(CreatorRecordableBeanWithCode.CREATOR_CODE, auth.getUser().getUsername()).//
//                            and(CreateDeptNameRecordableBeanWithCode.CREATE_DEPARTMENT_CODE, TermEnum.eq, auth.getPerson().getDeptCode());
//                    break;
//                case DEPARTMENT:
//                    term = Term.build(CreateDeptRecordableBeanWithCode.CREATE_DEPARTMENT_CODE, auth.getPerson().getDeptCode());
//                    break;
//                case CASCADE:
//                    term = Term.build(CreateDeptRecordableBeanWithCode.CREATE_DEPARTMENT_CODE, TermEnum.in, auth.getPerson().getCascadedDeptCodes());
//                    break;
//                case ALL:
//                    term = new Term();
//            }
//        }
        return term;
    }

}
